package lab02.test17;

public class Test {
    public static void main(String[] args) {

        //实例化
        int[] numbers = new int[10];
        numbers[0] = 13;
        numbers[1] = 9;
        numbers[2] = 56;
        numbers[3] = 34;
        numbers[4] = 26;
        numbers[5] = 46;
        numbers[6] = 16;
        numbers[7] = 39;
        numbers[8] = 50;
        numbers[9] = 98;

        //index下标:0-9
        int index;
        for(index=0;index<numbers.length;index++){
            System.out.println(numbers[index]);
        }

        //输出该数组中的最大值
        int max=0;
        for(int i=0;i<numbers.length;i++){
            if (numbers[i]>max) {
                max=numbers[i];
            }
        }
        System.out.println("max is " + max);

        int maxCab=0;
        for(int i=0;i<numbers.length;i++){
            if(numbers[i]>numbers[maxCab]){
                maxCab=i;
            }
        }
        System.out.println("最大值的下标为：" + maxCab);

        //输出该数组中的最小值
        int min=numbers[0];
        for(int i=0;i<numbers.length;i++){
            if(numbers[i]<min){
                min=numbers[i];
            }
        }
        System.out.println("min is " + min);

        int minCab=0;
        for(int i=0;i<numbers.length;i++){
            if(numbers[i]<numbers[minCab]){
                minCab=i;
            }
        }
        System.out.println("最小值的下标为："+minCab);

        //输出所有元素总和
        int sum=0;
        for(int i=0;i<numbers.length;i++){
            sum +=numbers[i];
        }
        System.out.println("sum is " + sum);


        }
    }

